﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Windows;
using iNet.Media.Imaging.Bmp;

namespace iNet.Media.Imaging
{
	/// <summary>
	/// BMP 影像解碼工作。
	/// </summary>
	public class BmpImageDecodeTask : BasicImageDecodeTask
	{
		#region 建構子
		/// <summary>
		/// 初始化新的 BmpImageDecodeTask 執行個體。
		/// </summary>
		public BmpImageDecodeTask()
			: base(ImageFormats.Bmp)
		{ }
		/// <summary>
		/// 初始化新的 BmpImageDecodeTask 執行個體。
		/// </summary>
		/// <param name="source">影像儲存來源。</param>
		public BmpImageDecodeTask(MediaStorage source)
			: base(ImageFormats.Bmp, source, 0, 0)
		{ }
		#endregion
		#region DecodePixelSize
		internal override Size<int> DecodePixelSize(Stream stream)
		{
			//讀取標頭
			if (stream.CanSeek)
				stream.Seek(14, SeekOrigin.Current);
			else
			{
				byte[] buffer = new byte[14];
				stream.Read(buffer, 0, 14);
			}
			BitmapInfoHeader infoHeader = new BitmapInfoHeader(stream);

			//取得大小
			return new Size<int>(infoHeader.Width, Math.Abs(infoHeader.Height));
		}
		#endregion
	}
}
